<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var obj = {
            userscore: [
                {
                    username: "老王",
                    score: 60
                },
                {
                    username: "老李",
                    score: 70
                },
                {
                    username: "老高",
                    score: 80
                },
                {
                    username: "老洪",
                    score: 90
                }
            ],
        };
         Object.defineProperties(obj, {
            sum: {
                get: function () {
                    let a = 0
                    obj.userscore.forEach(function (item) {
                        a += item.score
                    })
                    return a
                }
            },
            avg: {
                get: function () {
                    let avgScore = this.sum / this.userscore.length
                    return avgScore
                }
            }
        })
        console.log(obj.sum);
        console.log(obj.avg);
    </script>
</body>

</html>